package com.mew.slots.core.game.tjcs.service;

import cn.hutool.core.util.RandomUtil;
import com.mew.common.enm.SlotsPersistType;
import com.mew.common.enm.SlotsWinType;
import com.mew.common.entity.game.WinFree;
import com.mew.common.exception.ResponseCode;
import com.mew.slots.core.common.vo.StrategyGameVO;
import com.mew.slots.core.game.tjcs.room.TjcsBonusResponseMessage;

/**
 * @author dylin
 * @create 2021/5/31
 */
public class TjcsBonusService {
    private final int[][] freeRates=new int[][]{
            {2,4,6},
            {3,5,7},
            {5,7,9},
            {8,10,12},
            {10,20,30},
    };
    public TjcsBonusResponseMessage play(StrategyGameVO player){
        player.setNotRecord(SlotsPersistType.WinFree.code());
        TjcsBonusResponseMessage message=new TjcsBonusResponseMessage();
        WinFree winfree=player.getWinFree();
        if(winfree.getFrees()==0||winfree.getFreeNumber()>0){
            player.setStat(ResponseCode.BounsCanNotPlay.code());
            return message;
        }
        int freeType=player.getOtherMsg()[0];
        winfree.setFreeType(freeType);
        switch (freeType){
            case 1:
                winfree.setFreeNumber(25);
                winfree.setFreeCount(25);
                break;
            case 2:
                winfree.setFreeNumber(20);
                winfree.setFreeCount(20);
                break;
            case 3:
                winfree.setFreeNumber(15);
                winfree.setFreeCount(15);
                break;
            case 4:
                winfree.setFreeNumber(10);
                winfree.setFreeCount(10);
                break;
            case 5:
                winfree.setFreeNumber(5);
                winfree.setFreeCount(5);
                break;
            }
        winfree.setFreeRate(freeRates[freeType-1][RandomUtil.randomInt(3)]);
        message.setFreeRate(winfree.getFreeRate());
        player.setIconResult(String.valueOf(freeType));
        player.setWinType(SlotsWinType.Special.code());
        return message;
    }
}
